import os
from openai import OpenAI

from app.business.model_config import get_model_config
from app.initializer import init_config


def get_embedding(content: str):
    # model_api_key = get_model_config(model_name="qwen").model_api_key
    model_api_key = init_config().qwen_api_key
    print("model_api_key", model_api_key)
    client = OpenAI(
        api_key=model_api_key,  # 如果您没有配置环境变量，请在此处用您的API Key进行替换
        base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"  # 百炼服务的base_url
    )

    completion = client.embeddings.create(
        model="text-embedding-v4",
        input=content,
        dimensions=1024,  # 指定向量维度（仅 text-embedding-v3及 text-embedding-v4支持该参数）
        encoding_format="float"
    )
    # return completion.data[0].embedding

    return completion.data[0].embedding


def get_embedding_2(content: str):
    # model_api_key = get_model_config(model_name="qwen").model_api_key
    client = OpenAI(
        api_key="sk-fpvjksvlegtijgqawevvszsriubaqxuhakfsadlrxfinwawf",  # 如果您没有配置环境变量，请在此处用您的API Key进行替换
        base_url="https://api.siliconflow.cn/v1"  # 百炼服务的base_url
    )

    completion = client.embeddings.create(
        model="BAAI/bge-m3",
        input=content,
        dimensions=1024,  # 指定向量维度（仅 text-embedding-v3及 text-embedding-v4支持该参数）
        encoding_format="float"
    )
    # return completion.data[0].embedding

    return completion.data[0].embedding

# print(get_embedding_2("ssssss"))
# def get_embedding_list(contents):
#     client = OpenAI(
#         api_key=init_config().qwen_api_key,  # 如果您没有配置环境变量，请在此处用您的API Key进行替换
#         base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"  # 百炼服务的base_url
#     )
#
#     completion = client.embeddings.create(
#         model="text-embedding-v4",
#         input=contents,
#         dimensions=1024,  # 指定向量维度（仅 text-embedding-v3及 text-embedding-v4支持该参数）
#         encoding_format="float"
#     )
#     # return completion.data[0].embedding
#
#     return completion

# print(get_embedding("ssssss").id)
